package com.tianji.remark.task;

import com.tianji.remark.service.ILikedRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
@RequiredArgsConstructor
public class LikedTimesCheckTask {

    private static final List<String> BIZ_TYPES = List.of("QA","NOTE");//业务类型
    private static final int MAX_BIZ_SIZE = 30;//每次取的biz数量,防止一次性发送消息过多
    private final ILikedRecordService likedRecordService;

    //每20秒执行一次  将redis中某业务类型下面的点赞数发送消息 mq
//    @Scheduled(cron = "0/20 * * * * ?")//每间隔20s
    @Scheduled(fixedDelay = 40000)//每间隔20s
    public void checkLikedTimes(){
        for (String bizType : BIZ_TYPES){
            likedRecordService.readLikedTimesAndSentMessage(bizType,MAX_BIZ_SIZE);
        }
    }
}
